//
// Created by dddgzc on 2025/2/6.
//

#include "../include/StatusBar.h"

#include "DrawUtils.h"

void StatusBar::setAvatar(SDL_Texture* avatar) {
    this->avatar = avatar;
}

void StatusBar::setPosition(int x, int y) {
    this->point.x = x;
    this->point.y = y;
}

void StatusBar::setHp(int hp) {
    this->hp = hp;
}

void StatusBar::setMp(int mp) {
    this->mp = mp;
}

void StatusBar::onDraw(const Camera &camera) {
    draw(camera, avatar, point.x , point.y);
    drawRectangle(camera, point.x + 100, point.y + 10, width + 3 * 2, 36, SDL_Color(5, 5, 5));
    drawRectangle(camera, point.x + 100, point.y + 45, width + 3 * 2, 36, SDL_Color(5, 5, 5));

    drawRectangleFull(camera, point.x + 100, point.y + 10, width + 3, 33, SDL_Color(67, 47, 47));
    drawRectangleFull(camera, point.x + 100, point.y + 45, width + 3, 33, SDL_Color(67, 47, 47));

    float hp_bar_width = width * std::max(0, hp) / 100.0f;
    float mp_bar_width = width * std::min(100, mp) / 100.0f;

    drawRectangleFull(camera, point.x + 100, point.y + 10, hp_bar_width + 3, 33, SDL_Color(125, 0, 0, 255) );
    drawRectangleFull(camera, point.x + 100, point.y + 45, mp_bar_width + 3, 33, SDL_Color(0, 0, 125, 255) );
}
